#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>


static int m_qid = -1;
static int id = 896911;
//功能：创建消息队列
int  create_msgque(char *filename)
{
	key_t key;
	key=ftok(filename,id);
	m_qid = msgget(key, IPC_CREAT|0666);
	if(-1==m_qid)
	{
		perror("msgget failed:");
	}
	else
	{
		printf("qid=%d\n",m_qid);
	}

	return m_qid;
}

int send_msgque(unsigned char *msg,int size)
{
	int ret=msgsnd(m_qid, msg,size, 0);
	if(ret<0)
	{
		perror("msgsnd failed:");
	}

	return ret;
}

int rcv_msgque(unsigned char *msg,int size)
{
	int ret=msgrcv(m_qid, (void*)msg, size, 0, 0);
	if(ret<0)
	{
		perror("recv err:");
	}

	return ret;
}

int delete_msgque()
{
	int ret=msgctl(m_qid, IPC_RMID, 0);
	if(ret<0)
	{
		perror("msgctl failed:");
	}

	return ret;
}

